<template>
	<view>
		<z-paging style="background-color: #F2F1F6;" :auto="false" :fixed="true"  ref="paging" loadingMoreEnabled	
			v-model="dataList" @query="queryList" :loadingMoreCustomStyle="{paddingBottom:'200rpx'}"
			>
			<view class="row" style="padding: 20rpx 30rpx;align-items: stretch;flex-wrap: wrap;">
				<view v-for="(item,index) in dataList" :key="index" class="column commodity-item" style=""
					:style="index%2 !=0?'margin-left: 30rpx;':''"  @click.stop="openURL(item)">
					<image  style="width: 100%;margin: 10rpx auto;" :src="item.cover" mode="widthFix">
					</image>
					<view class="column" style="align-items: flex-start;padding: 10rpx 20rpx;">
						<view class="label-title" :contents="item.merchant=='TB'?'淘宝':'拼多多'">
							{{item.title}}
						</view>
						<view class="coupon-money" style="margin-top: 40rpx;">
							{{item.couponMoney}}元券
						</view>
						<view class="row" style="align-items: baseline;margin-top: 10rpx;">
							<text style="font-size: 24rpx;color: #989898;">券后</text>
							<text style="font-size: 36rpx;color: #D04900;">￥{{item.afterDiscountPrice.toFixed(2)}}</text>
							<text style="font-size: 24rpx;color: #989898;text-decoration: line-through;margin-left: 10rpx;">￥{{item.purchasePrice.toFixed(2)}}</text>
						</view>
					</view>
				</view>
			</view>
		</z-paging>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchText: "",
				dataList: [],
				firstLoaded: false,
				types:"TB"
			};
		},
		onLoad(data) {
			this.types = data.types
		},
		methods: {
			openURL(item){
				// #ifdef APP-PLUS
				if(item.merchant ==="TB"){
					this.$util.openTB(item.couponLink)
				}else {
					if(!uni.getStorageSync(this.$util.AUTH)){
						this.$api.prePage().isAuthorization();
						return
					}
					this.$util.doGet(`/api/mall/auth/pdd/goods/${item.sign}/promotion`,{}, {}, true).then(res => {
						console.log("拼多多链接",res.data)
						this.$util.openPDD(res.data.schemaUrl)
					}).catch(error => {
						console.log(error)
					})
				}
				// #endif
			},
			queryList(pageNo,pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				if(!this.searchText){
					return
				}
				const params = {
					pageNum:pageNo,
					pageSize:pageSize,
					merchant:this.types,
					keyword:this.searchText
				}
				this.$util.doGet('/api/mall/commodity/commodity/list',params, {}, true).then(res => {
					if (res.data.length ==0) {
						this.$refs.paging.complete([]);
						this.firstLoaded = true;
					}else {
						this.$refs.paging.complete(res.data);
						this.firstLoaded = true;
					}
				}).catch(error => {
					console.log(error)
				})
			},
		},
		onNavigationBarSearchInputClicked(){
			console.log("点击")
		},
		onNavigationBarButtonTap(val) {
			this.queryList(1,10);
		},
		onNavigationBarSearchInputConfirmed(){
			console.log("搜索")
			this.queryList(1,10);
			uni.hideKeyboard();//隐藏软键盘
		},
		onNavigationBarSearchInputChanged(val) {
			this.searchText = val.text
			if(!this.searchText){
				this.$refs.paging.complete([]);
				this.$refs.paging.reload();
				return
			}
		}
	}
</script>

<style lang="scss">
	.commodity-item {
		width: 330rpx;
		background-color: #FFFFFF;
		padding-bottom: 10rpx;
		border-radius: 5rpx;
		margin-bottom: 35rpx;
	}

	.label-title {
		font-size: 30rpx;
		height: 80rpx;
		overflow: hidden;
		text-overflow: clip;
		display: -webkit-box;
		// -webkit-line-clamp: 2;
		// -webkit-box-orient: vertical;

		&:before {
			content: attr(contents);
			padding: 5rpx 10rpx;
			text-align: center;
			background: linear-gradient(to right, #F2183A, #EC4B58, #EB7D73);
			border-radius: 8rpx;
			font-size: 24rpx;
			color: #FFFFFF;
			margin-right: 10rpx;
		}
	}

	.coupon-money {
		padding: 10rpx 8rpx;
		background: linear-gradient(to right, #F2183A, #EC4B58, #EB7D73);
		border-radius: 8rpx;
		font-size: 24rpx;
		color: #FFFFFF;
	}
</style>
